using System;
using System.Collections.Generic;
using System.Text;
using Csla.Data;

namespace MinaspetroLibrary.FornecedorPack
{
    [Serializable()]
    public class FornecedorChildInfo : Csla.ReadOnlyBase<FornecedorChildInfo>
    {
        #region Business Properties and Methods

        //declare members

        private Guid _id = Guid.NewGuid();

        private string _nome = string.Empty;

        private string _endereco = string.Empty;

        private string _bairro = string.Empty;

        private string _cEP = string.Empty;

        private string _cidade = string.Empty;

        private string _estado = string.Empty;

        private string _telefone = string.Empty;

        private string _contato = string.Empty;

        private string _logo = string.Empty;

        private Guid _setorId = Guid.Empty;

        private string _Setor = string.Empty;

        private string _Site = string.Empty;

        [System.ComponentModel.DataObjectField(true, true)]
        public Guid Id
        {
            get
            {
                return _id;
            }
        }

        public string Nome
        {
            get
            {
                return _nome;
            }
        }

        public string Endereco
        {
            get
            {
                return _endereco;
            }
        }

        public string Bairro
        {
            get
            {
                return _bairro;
            }
        }

        public string CEP
        {
            get
            {
                return _cEP;
            }
        }

        public string Cidade
        {
            get
            {
                return _cidade;
            }
        }

        public string Estado
        {
            get
            {
                return _estado;
            }
        }

        public string Telefone
        {
            get
            {
                return _telefone;
            }
        }

        public string Contato
        {
            get
            {
                return _contato;
            }
        }

        public string Logo
        {
            get
            {
                return _logo;
            }
        }

        public string LogoString
        {
            get
            {
                if (_logo.Contains("_"))
                    return _logo.Substring(_logo.IndexOf("_") + 1);
                return _logo;
            }
        }

        public Guid SetorId
        {
            get
            {
                return _setorId;
            }
        }

        public string SetorString
        {
            get
            {
                return _Setor;
            }
        }

        public string Site
        {
            get
            {
                return _Site;
            }
        }


        protected override object GetIdValue()
        {
            return _id.ToString();
        }

        #endregion //Business Properties and Methods

        #region Authorization Rules
        protected override void AddAuthorizationRules()
        {
            //TODO: Define authorization rules in FornecedorChildInfo

        }

        #endregion //Authorization Rules

        #region Factory Methods
        internal static FornecedorChildInfo GetFornecedorChildInfo(SafeDataReader dr)
        {
            return new FornecedorChildInfo(dr);
        }

        private FornecedorChildInfo(SafeDataReader dr)
        {
            Fetch(dr);
        }
        #endregion //Factory Methods

        #region Data Access

        #region Data Access - Fetch
        private void Fetch(SafeDataReader dr)
        {
            FetchObject(dr);

            //load child object(s)
            FetchChildren(dr);

        }

        private void FetchObject(SafeDataReader dr)
        {
            _id = new Guid(dr["Id"].ToString());
            _nome = dr.GetString("Nome");
            _endereco = dr.GetString("Endereco");
            _bairro = dr.GetString("Bairro");
            _cEP = dr.GetString("CEP");
            _cidade = dr.GetString("Cidade");
            _estado = dr.GetString("Estado");
            _telefone = dr.GetString("Telefone");
            _contato = dr.GetString("Contato");
            _logo = dr.GetString("Logo");
            _setorId = new Guid(dr["SetorId"].ToString());
            _Setor = dr.GetString("Setor");
            _Site = dr.GetString("Site");

        }

        private void FetchChildren(SafeDataReader dr)
        {
        }
        #endregion //Data Access - Fetch
        #endregion //Data Access
    }
}
